
"""
    其它表
"""


from django.db import models


class SoftModel(models.Model):

    """
        付费软件
    """
    sub_asset_type_choice = (
        (0, '操作系统'),
        (1, '办公软件'),
        (2, '开发软件'),
        (3, '业务软件'),
    )

    sub_asset_type = models.SmallIntegerField(choices=sub_asset_type_choice, default=0, verbose_name="软件类型")
    license_num = models.IntegerField(default=1, verbose_name="授权数量")
    version = models.CharField(max_length=64, unique=True, help_text='例如: RedHat release 7 (Final)',
                               verbose_name='软件/系统版本')
    time = models.DateTimeField(auto_now_add=True, verbose_name=u'创建日期')

    def __str__(self):
        return self.get_sub_asset_type_display()

    class Meta:
        app_label = 'cmdb'
        ordering = ['-time']
        verbose_name = '软件/系统'
        verbose_name_plural = "软件/系统"


class NewAssetApprovalZoneModel(models.Model):

    """
        新资产待审批区
    """

    asset_type_choice = (
        ('server', '服务器'),
        ('network', '网络设备'),
        ('storage', '存储设备'),
        ('security', '安全设备'),
        ('software', '软件资产'),
    )

    sn = models.CharField(max_length=128, unique=True, verbose_name=u'资产SN号')  # 此字段必填
    asset_type = models.CharField(choices=asset_type_choice, default='server', max_length=64, blank=True, null=True,
                                  verbose_name='资产类型')
    manufacturer = models.CharField(max_length=64, blank=True, null=True, verbose_name='生产厂商')
    model = models.CharField(max_length=128, blank=True, null=True, verbose_name='型号')
    ram_size = models.PositiveIntegerField(blank=True, null=True, verbose_name='内存大小')
    cpu_model = models.CharField(max_length=128, blank=True, null=True, verbose_name='CPU型号')
    cpu_count = models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='CPU物理数量')
    cpu_core_count = models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='CPU核心数量')
    os_distribution = models.CharField(max_length=64, blank=True, null=True, verbose_name='发行商')
    os_type = models.CharField(max_length=64, blank=True, null=True, verbose_name='系统类型')
    os_release = models.CharField(max_length=64, blank=True, null=True, verbose_name='操作系统版本号')
    data = models.TextField(verbose_name='资产数据')  # 此字段必填
    c_time = models.DateTimeField(auto_now_add=True, verbose_name='汇报日期')
    m_time = models.DateTimeField(auto_now=True, verbose_name='数据更新日期')
    approved = models.BooleanField(default=False, verbose_name='是否批准')

    def __str__(self):
        return self.sn

    class Meta:
        app_label = 'cmdb'
        ordering = ['-c_time']
        verbose_name = u'新上线待批准资产'
        verbose_name_plural = verbose_name

